# 使用OpenCV 寻找 自动查找 和 绘制角
import numpy as np
import cv2
import matplotlib.pyplot as plt
import matplotlib.image as mpimg

# 初始化对象点
nx = 8 #TODO: 输入x中的内角数
ny = 6 #TODO: 输入y中的内角数

# 读取图象
fname = 'calibration_test/calibration_test.png'
img = cv2.imread(fname)

# 通道转换
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# 找到图象的四周
ret, corners = cv2.findChessboardCorners(gray, (nx, ny), None)

# 如果找到 可视化
if ret == True:
    # 可视化
    cv2.drawChessboardCorners(img, (nx, ny), corners, ret)
    plt.imshow(img)
    plt.show()

# 保存
r, g, b = cv2.split(img)
result = cv2.merge((b, g, r))
cv2.imwrite("calibration_test/output_calibration_test.png", result)
